﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

using XMK.Tadong.Model;
using XMK.Utils;
using XMK.Framework.DataAccess;

namespace XMK.Tadong.DataSync.Data
{
    /// <summary>
    /// 空间文档数据访问类
    /// </summary>
    public class SpaceFileData
    {
        /// <summary>
        /// 数据库连接
        /// </summary>
        protected DbProvider dbProvider;

        public SpaceFileData(DbProvider dbProvider)
        {
            this.dbProvider = dbProvider;

        }

        public List<XMKFileInfo> QueryByGreaterThanID(Int64 fileID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendFormat(@"SELECT * FROM TB_PERSON_FILE WHERE FILE_ID = {0}", fileID);
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            IDataReader reader = DbHelper.ExecDataReader(dbProvider, cmd.DbCmdInfo);
            List<XMKFileInfo> fileInfoList = new List<XMKFileInfo>();
            
            while(reader.Read())
            {
                fileInfoList.Add(new XMKFileInfo
                {
                    FILE_ID = ParseHelper.Parse<long>(reader.GetValue(reader.GetOrdinal("FILE_ID"))),
                    FILE_NAME = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("FILE_NAME"))),
                    FILE_EXT = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("FILE_EXT"))),
                    FILE_CRT_TIME = ParseHelper.Parse<DateTime>(reader.GetValue(reader.GetOrdinal("FILE_CRT_TIME"))),
                    KEYW = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("KEYW"))),
                    UPD_TIME = ParseHelper.Parse<DateTime>(reader.GetValue(reader.GetOrdinal("UPD_TIME"))),
                    FILE_TYPE = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("FILE_TYPE"))),
                    FILE_ABST = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("FILE_ABST"))),
                    CREATE_TIME = ParseHelper.Parse<DateTime>(reader.GetValue(reader.GetOrdinal("CREATE_TIME"))),
                    SAVE_PATH = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("SAVE_PATH"))),
                    USER_ID = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("USER_ID"))),
                    FILE_AUTHOR = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("FILE_AUTHOR"))),
                    FILE_VERSION = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("FILE_VERSION"))),
                    DEST_OBJ = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("DEST_OBJ"))),
                    BIZ_OBJ = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("BIZ_OBJ"))),
                    SECRET_LVL = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("SECRET_LVL"))),
                    LANG_TYPE = ParseHelper.Parse<string>(reader.GetValue(reader.GetOrdinal("LANG_TYPE"))),
                });
            }
            return fileInfoList;
        }
    }
}
